ie4 = (document.all)? true:false

var expDays = 3;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*30*24*60*60*1000));

function switchframe(myobj) {
  if (ie4) {
    if (myobj.style.display=='' || myobj.style.display=='block') {
      hide(myobj);
    } else {
      show(myobj);
    }
  } else {
    if (myobj.style.display=='' || myobj.style.display=='block') {
      hide(myobj);
    } else {
      show(myobj);
    }
  }
}

function show(myobj) {
  if (ie4) {
    myobj.style.display='';
  } else {
    if (myobj) {
      myobj.style.display='';
    }
  }
}

function hide(myobj) {
  if (ie4) {
    myobj.style.display='none';
  } else {
    myobj.style.display='none';
  }
}



function switch_overlay(el) {
  if (el)
   el.style.visibility = (el.style.visibility == "visible") ? "hidden" : "visible";
}
function show_overlay(el) {
  if (el)
   el.style.visibility = "visible";
}
function hide_overlay(el) {
  if (el)
   el.style.visibility = "hidden";
}


function openwindow(url,winname,wid,hei) {
    win = window.open(url,winname,"menubar=0,toolbar=0,location=yes,scrollbars=yes,resizable=yes,top=10,left=10,height="+hei+",width="+wid);
    //parent.maincontainer.location=url;
    window.win.focus();
}
function closewindow() {
  window.close();
}

function jsloadingscreen() {
  lc = document.getElementById("loadingcontainer_overlay");
  pc = document.getElementById("processingcontainer_overlay");
  if (lc)
   lc.style.visibility="hidden";
  if (pc)
   pc.style.visibility="hidden";
  show(document.getElementById('maincontainer'));
  
}
function jsshowloadingscreen() {
  pc = document.getElementById("processingcontainer_overlay");
  if (pc)
    pc.style.visibility="visible";
}


function add_post_action(postaction) {
  if (document.getElementById('post_action')) {
    if (document.getElementById('post_action').value!='') {
      document.getElementById('post_action').value=document.getElementById('post_action').value+','+postaction;
    } else {
      document.getElementById('post_action').value=postaction;
    }
  }
}

function loadingcontainer_overlay() {
  el = document.getElementById("loadingcontainer_overlay");
  if (el)
   el.style.visibility = (el.style.visibility == "visible") ? "hidden" : "visible";
}
function processingcontainer_overlay() {
  el = document.getElementById("loadingcontainer_overlay");
  if (el)
   el.style.visibility = (el.style.visibility == "visible") ? "hidden" : "visible";
}
function captcha_overlay() {
  el = document.getElementById("captcha_overlay");
  if (el) {
    el.style.visibility = (el.style.visibility == "visible") ? "hidden" : "visible";
    if (el.style.visibility=="visible") {
      document.getElementById("captcha_val").value='';
      document.getElementById("captcha_val").focus();
    }
  }
}

function captcha_action(captcha_actionlist) {
  captcha_overlay();
  if (document.getElementById('captcha_actionlist')) 
   document.getElementById('captcha_actionlist').value=captcha_actionlist;
}
function captcha_overlay_auth(captchastr,captchaid) {
  sajax_request_type = 'POST';
  x_captcha_overylay_auth(captchastr,captchaid,document.getElementById('captcha_actionlist').value,captcha_overlay_auth_cb);
  sajax_request_type = '';
}
function captcha_overlay_auth_cb(val) {
  if (val[0]!='') {
    alert (val[0]);
  }
  if (val[1]!='') {
    eval(val[1]);
  }
}


function default_cb(val) {
  document.getElementById(val[0]['load_containername']).innerHTML=val[0]['load_list'];
}
function cngpg(runcmd,containername,listview,gotopg,sendparams) {
  if (gotopg=='' || gotopg<1) { gotopg=1; }


  //document.getElementById(containername).innerHTML='<center>...PROCESSING...</center>';

  sajax_request_type = 'POST';
  x_grabdata(runcmd,containername,listview,gotopg,sendparams,cngpg_cb);
  sajax_request_type = '';
}
function cngpg_cb(val) {
  tmppgcnt=new Number(val[0]['load_listpagecnt']);
  if (tmppgcnt<1) { tmppgcnt=1; }

  document.getElementById(val[0]['load_containername']).innerHTML=val[0]['load_list'];
  document.getElementById('pagelistpg'+val[0]['load_containername']).innerHTML=val[0]['load_listpage'];
  document.getElementById('pagelistcnt'+val[0]['load_containername']).innerHTML=tmppgcnt;

  if (document.getElementById('pagelist'+val[0]['load_containername']).length<tmppgcnt) {
    for (v=document.getElementById('pagelist'+val[0]['load_containername']).length+1;v<=tmppgcnt;v++) {
      document.getElementById('pagelist'+val[0]['load_containername']).options[v-1] = new Option(v);
    }
  }

  for (v=tmppgcnt;v<document.getElementById('pagelist'+val[0]['load_containername']).length;v++) {
    if (document.getElementById('pagelist'+val[0]['load_containername']).options[v].value=val[0]['load_listpage']) { document.getElementById('pagelist'+val[0]['load_containername']).selectedIndex=v; }
  }

  if (document.getElementById('pagelist'+val[0]['load_containername']).length>tmppgcnt) {
    for (v=document.getElementById('pagelist'+val[0]['load_containername']).length;v>=tmppgcnt;v--) {
      document.getElementById('pagelist'+val[0]['load_containername']).options[v]=null;
    }
  }
}

function up(inp, typ) {
  if (typ=='hour') {
    curnum = new Number(inp.value);
    curnum++;
    if (curnum==13) { curnum=1; }
    inp.value=curnum;
  }
  if (typ=='minute') {
    curnum = new Number(inp.value);
    if (curnum>0 && curnum<5) { curnum=5; }
    else if (curnum>5 && curnum<10) { curnum=10; }
    else if (curnum>10 && curnum<15) { curnum=15; }
    else if (curnum>15 && curnum<20) { curnum=20; }
    else if (curnum>20 && curnum<25) { curnum=25; }
    else if (curnum>25 && curnum<30) { curnum=30; }
    else if (curnum>30 && curnum<35) { curnum=35; }
    else if (curnum>35 && curnum<40) { curnum=40; }
    else if (curnum>40 && curnum<45) { curnum=45; }
    else if (curnum>45 && curnum<50) { curnum=50; }
    else if (curnum>50 && curnum<55) { curnum=55; }
    else if (curnum>55 && curnum<60) { curnum=0; }
    else { curnum=curnum+5; }
    if (curnum>59) { curnum=0; }
    inp.value=curnum;
  }
  if (typ=='ampm') {
    if (inp.value=='AM') { inp.value='PM'; } else { inp.value='AM'; }
  }
  if (typ=='date') {

	strftime = new String(inp.value);
	arrtime = strftime.split("/");
	numyr = new Number(arrtime[0]);
	nummon = new Number(arrtime[1]);
	numday = new Number(arrtime[2]);

	if (nummon==1 || nummon==3 || nummon==5 || nummon==7 || nummon==8 || nummon==10 || nummon==12) {
	  if (numday<31) {
	    numday = numday+1;
	  } else if (numday==31) {
	    numday = 1;
	    if (nummon<12) {
	      nummon=nummon+1;
	    } else {
	      nummon=1;
	      numyr=numyr+1;
	    }
	  }
	} else if (nummon==4 || nummon==6 || nummon==9 || nummon==11) {
	  if (numday<30) {
	    numday = numday+1;
	  } else if (numday==30) {
	    numday = 1;
	    if (nummon<12) {
	      nummon=nummon+1;
	    } else {
	      nummon=1;
	      numyr=numyr+1;
	    }
	  }
	} else if (nummon==2) {
	  if (numday<28) {
	    numday = numday+1;
	  } else if (numday==28) {
	    numday = 1;
	    if (nummon<12) {
	      nummon=nummon+1;
	    } else {
	      nummon=1;
	      numyr=numyr+1;
	    }
	  }
	}

    inp.value = numyr+'/';
    if (nummon<10) { inp.value = inp.value + '0'; }
    inp.value = inp.value +nummon+'/';
    if (numday<10) { inp.value = inp.value + '0'; }
    inp.value = inp.value + numday;
  }
}


function down(inp, typ) {
  if (typ=='hour') {
    curnum = new Number(inp.value);
    curnum--;
    if (curnum==13) { curnum=1; }
    if (curnum==0 || curnum==-1) { curnum=12; }
    inp.value=curnum;
  }
  if (typ=='minute') {
    curnum = new Number(inp.value);
    if (curnum==0) { curnum=55; }
    else if (curnum>0 && curnum<5) { curnum=0; }
    else if (curnum>5 && curnum<10) { curnum=5; }
    else if (curnum>10 && curnum<15) { curnum=10; }
    else if (curnum>15 && curnum<20) { curnum=15; }
    else if (curnum>20 && curnum<25) { curnum=20; }
    else if (curnum>25 && curnum<30) { curnum=25; }
    else if (curnum>30 && curnum<35) { curnum=30; }
    else if (curnum>35 && curnum<40) { curnum=35; }
    else if (curnum>40 && curnum<45) { curnum=40; }
    else if (curnum>45 && curnum<50) { curnum=45; }
    else if (curnum>50 && curnum<55) { curnum=50; }
    else if (curnum>55 && curnum<60) { curnum=55; }
    else { curnum=curnum-5; }
    if (curnum<0) { curnum=0; }
    inp.value=curnum;
  }
  if (typ=='ampm') {
    if (inp.value=='AM') { inp.value='PM'; } else { inp.value='AM'; }
  }
  if (typ=='date') {

	strftime = new String(inp.value);
	arrtime = strftime.split("/");
	numyr = new Number(arrtime[0]);
	nummon = new Number(arrtime[1]);
	numday = new Number(arrtime[2]);

	if (numday>1) {
	  numday = numday-1;
	} else if (numday==1) {
	  if (nummon>1) {
	    nummon=nummon-1
	    if (nummon==1 || nummon==3 || nummon==5 || nummon==7 || nummon==8 || nummon==10 || nummon==12) { numday=31 }
	    else if (nummon==4 || nummon==6 || nummon==9 || nummon==11) { numday = 30; }
	    else if (nummon==2) { numday = 28; }
	  } else {
	    nummon=12;
	    numyr=numyr-1
            numday=31
	  }
	}

    inp.value = numyr+'/';
    if (nummon<10) { inp.value = inp.value + '0'; }
    inp.value = inp.value +nummon+'/';
    if (numday<10) { inp.value = inp.value + '0'; }
    inp.value = inp.value + numday;
  }
}

var expHours = 3;
var exp = new Date();
exp.setTime(exp.getTime() + (expHours*60*60*1000));

function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  }
  return null;
}

function SetCookie (name, value, expires, path) {
  var argv = SetCookie.arguments;
  var argc = SetCookie.arguments.length;
  var expires = (argc > 2) ? argv[2] : null;
  var path = (argc > 3) ? argv[3] : null;
  var domain = (argc > 4) ? argv[4] : null;
  var secure = (argc > 5) ? argv[5] : false;
  document.cookie = name + "=" + escape (value) +
  ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
  ((path == null) ? "" : ("; path=" + path)) +
  ((domain == null) ? "" : ("; domain=" + domain)) +
  ((secure == true) ? "; secure" : "");
}

function DeleteCookie (name) {
  var exp = new Date();
  exp.setTime (exp.getTime() - 1);
  var cval = GetCookie (name);
  document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}